package com.yang.doctorrecruitment.dao;

import com.yang.doctorrecruitment.dto.ReleaseJob;
import com.yang.doctorrecruitment.utils.DBManager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class CollectionDAO {
    private static Connection conn;
    public static boolean InsertCollection(String UserID,String JobID,String Itime){
        conn= DBManager.getconnection();
        ResultSet res=null;
        PreparedStatement statement=null;
        String sql="insert into collection values(?,?,?)";

        try{
            statement=conn.prepareStatement(sql);
            statement.setString(1,UserID);
            statement.setString(2,JobID);
            statement.setString(3,Itime);
            int count=statement.executeUpdate();
            if(count>=1){
                return true;
            }

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            DBManager.closeAll(conn,statement,res);
        }
        return false;
    }

    public static boolean SelectCollection(String UserID,String JobID){
        conn= DBManager.getconnection();
        ResultSet res=null;
        PreparedStatement statement=null;
        String sql="select * from collection where UserID=? and JobID=?";

        try{
            statement=conn.prepareStatement(sql);
            statement.setString(1,UserID);
            statement.setString(2,JobID);
            res=statement.executeQuery();
           while(res.next()){
               return true;
           }

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            DBManager.closeAll(conn,statement,res);
        }
        return false;
    }
}
